<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    div{
      text-align: left;
    }
    .red{
      color: red;
    }
  </style>
  <script src="http://simple-vue.fanchao.site/index.js"></script>
  <!-- <script src="./index.js"></script> -->
</head>
<body>
  <div id="app">
    <div @click="clickName"><span class='red'>(点击事件) </span> 姓名:{{ name }}</div>
    <div>年龄:{{ age }} 岁</div>
    <input v-model='age' type="text" v-on:keydown="handleKeyUp" />(按键盘上和下键对年龄进行快速加减操作)
    <div><span class='red'>(计算属性) </span>年龄段:{{ type }}</div>
  </div>
  <script>
    new Vue({
      el: '#app',
      data: {
        name: 'fanchao',
        age: 24
      },
      computed: {
        type () {
          return this.age < 5
            ? '婴儿' : this.age < 12
              ? '儿童' : this.age < 22
                ? '青少年' : this.age < 44
                  ? '青年' : this.age < 59
                    ? '中年' : this.age < 100
                      ? '老年人' : '长寿'
        }
      },
      methods: {
        handleKeyUp (e) {
          if (e.keyCode === 38) {
            this.age++
            e.preventDefault()
          } else if (e.keyCode === 40) {
            if(this.age < 1) return
            this.age--
          }
        },
        clickName () {
          this.name = 'name have been click'
        }
      },
      mounted () {
        console.log('mounted')
      }
    })
  </script>
</body>
</html>